package entity;

import java.awt.Point;

import representation.EntityRepresentation;
import representation.PlayerRepresentation;

import controller.Controller;
import controller.PlayerController;
import enums.Direction;


public class Player extends Entity {
	
	private PlayerController controller;
	private int speed;
	private int diagSpeed;
	private Point location;
	private PlayerRepresentation representation;

	public Player(PlayerController controller) {
		this.controller = controller;
		this.speed = 20;
		this.diagSpeed = (int) Math.floor((speed / Math.sqrt(2)));
		this.location = new Point(250, 250);
		this.representation = new PlayerRepresentation(this);
	}

	public void update() {
		Direction direction = this.controller.getDesiredDirection();
		switch (direction) {
		case STILL:
		default:
			return;
		case N:
			if (canMoveUp()) {
				location.y -= speed;
			}
			break;
		case NW:
			if (canMoveUp()) {
				location.y -= diagSpeed;
			}
			if (canMoveLeft()) {
				location.x -= diagSpeed;
			}
			break;
		case W:
			if (canMoveLeft()) {
				location.x -= speed;
			}
			break;
		case SW:
			if (canMoveDown()) {
				location.y += diagSpeed;
			}
			if (canMoveLeft()) {
				location.x -= diagSpeed;
			}
			break;
		case S:
			if (canMoveDown()) {
				location.y += speed;
			}
			break;
		case SE:
			if (canMoveDown()) {
				location.y += diagSpeed;
				location.x += diagSpeed;
			}
			break;
		case E:
			if (canMoveRight()) {
				location.x += speed;
			}
			break;
		case NE:
			if (canMoveUp()) {
				location.y -= diagSpeed;
			}
			if (canMoveRight()) {
				location.x += diagSpeed;
			}
		}
	}
	
	private boolean canMoveUp() {
		return true;
	}
	
	private boolean canMoveLeft() {
		return true;
	}
	
	private boolean canMoveDown() {
		return true;
	}
	
	private boolean canMoveRight() {
		return true;
	}

	public Controller getController() {
		return this.controller;
	}
	
	public EntityRepresentation getRepresentation() {
		return this.representation;
	}
	
	public Point getLocation() {
		return this.location;
	}

}
